package Graph;

import GraphCore.VertexInterface;
import java.util.ArrayList;
import java.util.Iterator;



/**
 * @author rodacki, Tiago,Ruan
 * Objeto que representa a Vertice do Grafo.
 */
public class Vertex implements VertexInterface {
    private int id; //id do vertice
    private int degree = 0; //grau do vertice
    private ArrayList<Edge> edges = new ArrayList(); //lista de arestas
    private Boolean isAdjacent; //booleano se é adjacente
    
    /**
     * 
     * Construtor 
     */
    public Vertex(int id){
        this.id = id;
    }

    /*
     * get ID
     */
    @Override
    public int getId() {
        return this.id;
    }

    /**
     * 
     * get Degree
     */
    @Override
    public int getDegree() {
        return degree;
    }
    

    /*
     * Método que retorna se um vertice é adjacente desse vertice em questão
     */
    @Override
    public boolean isAdjacent(Vertex vj) {
        
        if (!edges.isEmpty()){
            for(int i = 0; i < getEdges().size(); i++){
                if (getEdges().get(i).getVj() == vj)
                    return true;
            }
        }
        return false;
    }

    /**
     * @return the edges
     */
    public ArrayList<Edge> getEdges() {
        return edges;
    }

    /**
     * @param edges the edges to set
     */
    public void setEdges(ArrayList<Edge> edges) {
        this.edges = edges;
    }

    /**
     * Lista de vertices adjacentes a aquele vertice.
     */
    @Override
    public ArrayList<Vertex> adj() {
        ArrayList<Vertex> adjacents = new ArrayList();
            for (Edge edge: getEdges()){
                    if (edge.getVi().equals(this))
                            adjacents.add(edge.getVj());
            }
        return adjacents;
    }

    /**
     * ToString do Vertice
     */
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append("Vertex{ id=" );
        sb.append(id);
        sb.append(" adj = ");
        for (Iterator<Vertex> it = adj().iterator(); it.hasNext();) {
            Vertex vertex = it.next(); 
            sb.append(vertex.id).append(",");
        }
        sb.append("}\n");
        return sb.toString();
    }

 
    @Override
    public int setDegree(int degree) {
        return this.degree = degree;
    }


}